
const netWorked = require('../../utils/netWork.js')
const Config = require('../../utils/confing.js')
// pages/Purchase/Order/Index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date: '2015-01-01',//默认起始时间  
    date2: '2022-01-01',//默认结束时间 
    shenhe: "全部",
    showsh: false,
    data: [],
    pagesize: 0,
    shenheshow: false,
  },
  //编辑
  shenheok(e) {
    // if (e.currentTarget.dataset.shenif=="已审核" ){
    //   wx.showToast({
    //     title: '该订单已经审核',
    //     icon: "none",
    //   })
    // }else{
    // }
    wx.navigateTo({
      url: '/pages/management/particulars/index?id=' + e.currentTarget.dataset.shenheok

    })

  },
  //审核框
  shenheshow() {
    let _this = this
    _this.setData({

      shenheshow: true,
    })
  },
  //选中审核状态
  onSearch(e) {
    let _this = this

    if (e.currentTarget.dataset.shen == "-1") {
      wx.request({
        url: Config.BaseUrl + 'OrderManagement/NeedGoods',
        method: "POST",

        success: function (res) {
          let data = res.data
          _this.setData({
            data: res.data,
            shenheshow: false,
            shenhe: "全部",
          })

          if (res.data.length >= 10) {
            _this.setData({
              pagesize: 10,
            })
          } else[
            _this.setData({
              pagesize: res.data.length,
            })
          ]


        }
      })
    }

    else if (e.currentTarget.dataset.shen == "1") {

      wx.request({
        url: Config.BaseUrl + 'OrderManagement/NeedGoods?where=approve_flag=' + 2 + '',
        method: "POST",
        success: function (res) {
          let data = res.data
          _this.setData({
            shenheshow: true,
            data: res.data,

            shenheshow: false,
            shenhe: "未审核",
          })

          if (res.data.length >= 10) {
            _this.setData({
              pagesize: 10,
            })
          } else {
            _this.setData({
              pagesize: res.data.length,
            })
          }
        }
      })



    } else {
      _this.setData({
        shenhe: "已审核",
      })
      wx.request({
        url: Config.BaseUrl + 'OrderManagement/NeedGoods?where=approve_flag=' + 1 + '',
        method: "POST",
        success: function (res) {
          let data = res.data
          _this.setData({
            data: res.data,
            shenheshow: false,

            shenhe: "已审核",
          })

          if (res.data.length >= 10) {
            _this.setData({
              pagesize: 10,
            })
          } else {
            _this.setData({
              pagesize: res.data.length,
            })
          }
        }
      })
    }

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    let _this = this
    wx.request({
      url: Config.BaseUrl + 'OrderManagement/NeedGoods',
      method: "POST",

      success: function (res) {
        console.log(res.data)
        let data = res.data
        _this.setData({
          data: res.data,
        })

        if (res.data.length >= 10) {
          _this.setData({
            pagesize: 10,
          })
        } else {
          _this.setData({
            pagesize: res.data.length,
          })
        }
      }
    })
  },
  //搜索
  onsou(e) {
    let _this = this;
    let where = "";
    if (_this.data.shenhe == "已审核") {
      where = "sheet_no like '%25" + e.detail + "%25' and approve_flag='1' ";
    } else if (_this.data.shenhe == "未审核") {
      where = "sheet_no like '%25" + e.detail + "%25' and approve_flag='2' ";
    } else {
      where = "sheet_no like '%25" + e.detail + "%25'";
    }

    console.log(where)
    wx.request({
      url: Config.BaseUrl + 'OrderManagement/NeedGoods?where=' + where,
      method: "POST",

      success: function (res) {
        console.log(res.data)
        let data = res.data
        _this.setData({
          data: res.data,
        })

        if (res.data.length >= 10) {
          _this.setData({
            pagesize: 10,
          })
        } else {
          _this.setData({
            pagesize: res.data.length,
          })
        }
      }
    })
  },
  //新增
  add() {
    wx.navigateTo({
      url: '/pages/management/particulars/index'

    })
  },
  // 时间
  bindDateChange(e) {
    let _this = this;
    _this.setData({
      date: e.detail.value,
    })
    let shen = "";
    if (_this.data.shenhe == "已审核") {
      shen = " and approve_flag='1' ";
    } else if (_this.data.shenhe == "未审核") {
      shen = " and approve_flag='2' ";
    }

    let where = "oper_date between '" + _this.data.date + " 00:00:00' and '" + _this.data.date2 + " 23:59:59' " + shen + "";

    console.log(where)

    netWorked.netWork({
      url: '/OrderManagement/NeedGoods?&where=' + where,
      method: "POST",
      success: function (res) {

        _this.setData({
          data: res.data,

        })

        if (res.data.length >= 10) {
          _this.setData({
            pagesize: 10,
          })
        } else {
          _this.setData({
            pagesize: res.data.length,
          })
        }
      }
    })



  },
  bindDateChange2(e) {
    let _this = this;
    _this.setData({
      date2: e.detail.value,
    })
    let shen = "";
    if (_this.data.shenhe == "已审核") {
      shen = " and approve_flag='1' ";
    } else if (_this.data.shenhe == "未审核") {
      shen = " and approve_flag='2' ";
    }

    let where = "oper_date between '" + _this.data.date + " 00:00:00' and '" + _this.data.date2 + " 23:59:59' " + shen + "";

    console.log(where)

    netWorked.netWork({
      url: '/OrderManagement/NeedGoods?&where=' + where,
      method: "POST",
      success: function (res) {

        _this.setData({
          data: res.data,

        })

        if (res.data.length >= 10) {
          _this.setData({
            pagesize: 10,
          })
        } else {
          _this.setData({
            pagesize: res.data.length,
          })
        }
      }
    })



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let _this = this
    if (_this.data.pagesize < _this.data.data.length) {

      if (_this.data.pagesize + 10 <= _this.data.data.length) {
        _this.setData({
          pagesize: _this.data.pagesize + 10,

        })
      } else {
        _this.setData({
          pagesize: _this.data.pagesize + (_this.data.data.length - _this.data.pagesize),

        })
      }

    }

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})